﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Theoreme.Samples.UnitTesting.Mocks.BLL
{
    /// <summary>
    /// Real implementation that will replace the dynamic mock in the Tests..
    /// </summary>
    public class RealPersonRepository : IPersonRepository
    {
       
        private List<Person> _list;

        /// <summary>
        /// Initializes a new instance of 
        /// the <see cref="RealPersonRepository"/> class,
        /// and builds a list of <see cref="Person"/>.
        /// </summary>
        public RealPersonRepository()
        {
            // Normally the list would be created from a real data-source (a database, file, or anything)..
            _list = new List<Person>()  {   new Person("1", "Wendy", "Whiner"),
                                            new Person("2", "Aaron", "Adams")
                                        };
        }

        /// <summary>
        /// Gets the list of <see cref="Person"/>
        /// </summary>
        /// <returns>The list of <see cref="Person"/>.</returns>
        public List<Person> GetPeople()
        {
            return _list;
        }

        /// <summary>
        /// Gets the <see cref="Person"/> by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>the Person for that id or null.</returns>
        public Person GetPersonById(string id)
        {
            var query = from person in _list
                            where person.Id == id             
                                select person;

            if (query.Count() == 0)
            {
                throw new ArgumentException("Invalid person id.");
            }

            return query.Single();
        }
    }
}
